import uniqueId from "@form-create/utils/lib/unique";
import {
  localeProps,
  makeOptionsRule,
  makeRequiredRule,
  makeTreeOptions,
} from "../../utils/index";

const label = "单选框";
const name = "radio";

export default {
  icon: "icon-radio",
  label,
  name,
  rule({ t }) {
    const opt = t("props.option");
    return {
      type: name,
      field: uniqueId(),
      title: t("components.radio.name"),
      info: "",
      effect: {
        fetch: "",
      },
      $required: false,
      props: {},
      options: makeTreeOptions(
        t("props.option"),
        { label: "label", value: "value" },
        1
      ),
    };
  },
  props(_, { t }) {
    return localeProps(t, name + ".props", [
      makeRequiredRule(),
      makeOptionsRule(t, "options"),
      {
        type: "switch",
        field: "disabled",
        title: "是否禁用",
      },
      {
        type: "select",
        field: "type",
        title: "按钮形式",
        value: "radio",
        options: [
          {
            label: "按钮",
            value: "button",
          },
          {
            label: "单选",
            value: "radio",
          },
        ],
      },
      {
        type: "select",
        field: "direction",
        title: "方向",
        value: "horizontal",
        options: [
          {
            label: "纵向",
            value: "vertical",
          },
          {
            label: "横向",
            value: "horizontal",
          },
        ],
      },
    ]);
  },
};
